package com.marion.zeus

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.bumptech.glide.Glide
import com.marion.zeus.config.WebId
import com.marion.zeus.databinding.ActivitySplashBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class SplashActivity : AppCompatActivity() {
    lateinit var splashBinding: ActivitySplashBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        splashBinding= ActivitySplashBinding.inflate(layoutInflater)

        setContentView(splashBinding.root)

        GlobalScope.launch(Dispatchers.Main) {
            var imaUrl =""
            ZusApplication.config.data?.modules?.forEach {
                if(it.webviewParameter!= null){
                    when(it.webviewId){
                        WebId.BASIC->{
                            imaUrl = it.webviewParameter!!.splashScreen?:""
                        }
                    }
                }
            }
            if(imaUrl.isNotEmpty()){
                Glide.with(this@SplashActivity).load(imaUrl).into(splashBinding.openAd)
            }
            repeat(6){
                splashBinding.tvCountDown.text = (6-it).toString()
                delay(1000)
            }

            startActivity(Intent(this@SplashActivity, MainActivity::class.java))
            finish()
        }


    }
}